package com.zj.executor;

import com.zj.mapping.BoundSql;
import com.zj.mapping.MappedStatement;
import com.zj.utils.Configuration;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class DefaultParameterHandler implements ParameterHandler {

//    private final TypeHandlerRegistry typeHandlerRegistry;

    private final MappedStatement mappedStatement;
    private final Object parameterObject;
    private BoundSql boundSql;
    private Configuration configuration;


    public DefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
        this.mappedStatement = mappedStatement;
        this.configuration = mappedStatement.getConfiguration();
//        this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
        this.parameterObject = parameterObject;
        this.boundSql = boundSql;
    }

    public Object getParameterObject() {
        return parameterObject;
    }

    public void setParameters(PreparedStatement ps)
            throws SQLException {
        List<Object> params= boundSql.getParameters();
        for(int i=0;i<params.size();i++){
            ps.setObject(i+1, params.get(i));
        }
    }

}